#!/bin/bash

# Expects the BBL source as the first argument followed by the bib entries
# to supress.
BBL_SOURCE=$1

NAMES=${@:2}

function getLineNumber {
    sed -ne "/$1/=" ${BBL_SOURCE}
}

for i in $@; do
    name=${i}
    lineNumber=`getLineNumber ${name}`
    if [ -n "${lineNumber}" ]; then
	echo "Supressing ${name} on line ${lineNumber}"
	sed -e '/./{H;$! d;}' -e "x;/${name}/d" ${BBL_SOURCE} > tmp.bbl
	sed -n "1,${lineNumber}p" tmp.bbl > tmp.before.bbl
	echo -e "\\\\bibitem{${name}}\nOmitted for blind review." > \
	    tmp.insert.bbl
	sed -n "${lineNumber},\$p" tmp.bbl > tmp.after.bbl
	cat tmp.before.bbl tmp.insert.bbl tmp.after.bbl > ${BBL_SOURCE}
    fi
done

rm -f tmp.bbl tmp.before.bbl tmp.insert.bbl tmp.after.bbl
